home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / DATABASE.DIR / 00086_Script_HYPERTEXT LINKING < prev    next >
Text File  |  1996-03-28  |  8KB  |  232 lines

  1. -- --------------------------------------------------------
  2. -- Handler checkIfClickedHyperLink checks if the user
  3. -- clicked on a hypertext.
  4.  
  5. on checkIfClickedHyperLink
  6.   global textSprite, currentTextCast, hypertextWords
  7.   
  8.   set currentTextCast = the castNum of sprite textSprite 
  9.   
  10.   set wordNumber = the mouseWord 
  11.   set clickedword = word wordNumber of field currentTextCast 
  12.   
  13.   set linkType = getHyperLinkType(wordNumber)
  14.   
  15.   if (linkType <> -1) then
  16.     processHyperLink(wordNumber, linkType)
  17.   end if
  18. end
  19.  
  20. -- --------------------------------------------------------
  21. -- Handler getHyperLinkType returns 1 if the user clicked
  22. -- on a hyperText link, 2 if the user clicked on a hyperMedia
  23. -- link, and -1 if the user did not click on a hyper link.
  24.  
  25. on getHyperLinkType wordNumber
  26.   -- note: must check for hypermedia link before hypertext link
  27.   -- because both are bold and hypermedia link also has a color
  28.   -- conditon. if hypertext check was done first, hypermedia links
  29.   -- would be processed as hypertext.
  30.   if isHyperMediaLink(wordNumber) then
  31.     return 2
  32.   else if isHyperTextLink(wordNumber) then
  33.     return 1
  34.   else
  35.     return -1
  36.   end if
  37. end
  38.  
  39. -- --------------------------------------------------------
  40. -- Handler processHyperLink processes the hyperlink.
  41.  
  42. on processHyperLink wordNumber, linkType
  43.   set hyperLinkWords = getHyperLinkWords(wordNumber)
  44.   hiliteHyperLinkwords(hyperLinkWords)
  45.   goHyperLink(hyperLinkWords, linkType)
  46. end
  47.  
  48. -- --------------------------------------------------------
  49. -- Handler isHyperTextLink returns TRUE if the given wordNumber of
  50. -- the given field is a hypertext link (defined by bold)
  51. -- and returns FALSE otherwise.
  52.  
  53. on isHyperTextLink wordNumber
  54.   global currentTextCast
  55.   
  56.   if (length(word wordNumber of field currentTextCast) > 1) then
  57.     set wordStyle = the textStyle of char 2 of word wordNumber of field currentTextCast
  58.   else
  59.     set wordStyle = the textStyle of word wordNumber of field currentTextCast
  60.   end if
  61.   
  62.   if (wordStyle contains "bold") then
  63.     return TRUE
  64.   else
  65.     return FALSE
  66.   end if 
  67. end
  68.  
  69. -- --------------------------------------------------------
  70. -- Handler isHyperMediaLink returns TRUE if the given wordNumber of
  71. -- the given field is a hypermedia link (defined by bold and foreColor
  72. -- of word clicked = hypermediaLinkColor) and returns FALSE otherwise.
  73.  
  74. on isHyperMediaLink wordNumber
  75.   global currentTextCast, hyperMediaLinkColor
  76.   
  77.   if (length(word wordNumber of field currentTextCast) > 1) then
  78.     set wordStyle = the textStyle of char 2 of word wordNumber of field currentTextCast
  79.   else
  80.     set wordStyle = the textStyle of word wordNumber of field currentTextCast
  81.   end if
  82.   
  83.   set wordColor = the foreColor of word wordNumber of field currentTextCast
  84.   
  85.   return (wordStyle contains "bold") and (wordColor = hyperMediaLinkColor)
  86. end
  87.  
  88. -- --------------------------------------------------------
  89. -- Handler goHyperLink calls the proper go hyperlink handler.
  90.  
  91. on goHyperLink hyperLinkWords, linkType
  92.   
  93.   if (linkType = 1) then -- hypertext
  94.     goHyperTextLink(hyperLinkWords)
  95.   else if (linkType = 2) then -- hypermedia
  96.     goHyperediaLink(hyperLinkWords)
  97.   end if
  98. end
  99.  
  100. -- --------------------------------------------------------
  101. -- Handler goHyperTextLink puts the hypertext link of the
  102. -- given word on stage
  103.  
  104. on goHyperTextLink hypertextWords
  105.   global clickedTopic, hypertextPhrase
  106.   
  107.   set hypertextPhrase = getHypertextPhrase(hypertextWords)
  108.   
  109.   set clickedTopic = hypertextPhrase
  110.   
  111.   if (the number of cast (clickedTopic && "TEXT1") = -1) then
  112.     set clickedTopic = getEquivalentTerm(clickedTopic)
  113.   end if
  114.   
  115.   resetCurrentPage
  116.   resetCurrentPicture
  117.   resetCurrentCaption
  118.   
  119.   showSelectedTopic
  120. end
  121.  
  122. -- --------------------------------------------------------
  123. -- Handler goHyperMediaLink puts the hypermedia link of the
  124. -- given word on stage
  125.  
  126. on goHyperediaLink hypertextWords
  127.   global clickedTopic,hypertextPhrase
  128.   
  129.   set hypertextPhrase = getHypertextPhrase(hypertextWords)
  130.   set clickedTopic = hypertextPhrase
  131.   
  132.   if (the number of cast (clickedTopic && "TEXT1") = -1) then
  133.     set clickedTopic = getEquivalentTerm(clickedTopic)
  134.   end if
  135.   
  136.   resetCurrentPage
  137.   resetCurrentPicture
  138.   resetCurrentCaption
  139.   
  140.   showSelectedMedia
  141. end
  142.  
  143. -- --------------------------------------------------------
  144. -- Handler getHyperLinkWords returns a list of the word
  145. -- numbers in the hypertext link that were clicked on.
  146.  
  147. on getHyperLinkWords wordNumber
  148.   global currentTextCast
  149.   
  150.   -- keep the list sorted
  151.   set hyperLinkWords = [wordNumber]
  152.   sort hyperLinkWords
  153.   
  154.   set linkStyle = the textStyle of word wordNumber of field currentTextCast
  155.   set linkColor = the foreColor of word wordNumber of field currentTextCast
  156.   
  157.   -- get all the words before the clickedWord that are part
  158.   -- of the hyperLink phrase.
  159.   repeat with i = (wordNumber - 1) down to 1
  160.     set theWord = word i of field currentTextCast
  161.     if (the textStyle of word i of field currentTextCast = linkStyle) and (the foreColor of word i of field currentTextCast = linkColor) and not(endsWithPunctuation(theWord)) then
  162.       add(hyperLinkWords, i)
  163.     else -- reached the beginning of the phrase
  164.       exit repeat
  165.     end if
  166.   end repeat
  167.   
  168.   -- If the clickedWord does not end with punctuation,
  169.   -- get all the words after the clickedWord that are part
  170.   -- of the hypertext phrase.
  171.   if not(endsWithPunctuation(word wordNumber of field currentTextCast)) then
  172.     repeat with i = (wordNumber + 1) to the number of words in field currentTextCast
  173.       if (the textStyle of word i of field currentTextCast = linkStyle) and (the foreColor of word i of field currentTextCast = linkColor) then
  174.         add(hyperLinkWords, i)
  175.         if endsWithPunctuation(word i of field currentTextCast) then
  176.           exit repeat
  177.         end if
  178.       else -- reached the end of the phrase
  179.         exit repeat
  180.       end if
  181.     end repeat
  182.   end if
  183.   
  184.   return hyperLinkWords
  185. end
  186.  
  187. -- --------------------------------------------------------
  188. -- Handler hiliteHyperLinkwords hilites the hyperLink words
  189. -- of the clicked on phrase.
  190.  
  191. on hiliteHyperLinkwords hypertextWords
  192.   global currentTextCast, hilitBackground, hypertextHiliteColor
  193.   
  194.   set numHypertextwords = count(hypertextWords)
  195.   set firstword = getAt(hypertextWords, 1)
  196.   set lastword = firstword + numHypertextwords - 1
  197.   
  198.   set oldForeColor = the foreColor of word firstWord of field currentTextCast
  199.   set the foreColor of word firstword to lastword of field currentTextCast = hypertextHiliteColor
  200.   
  201.   updateStage
  202.   
  203.   set the foreColor of word firstword to lastword of field currentTextCast = oldForeColor
  204. end
  205.  
  206. -- --------------------------------------------------------
  207. -- Handler getHypertextPhrase returns the hypertext phrase
  208. -- that was clicked.
  209.  
  210. on getHypertextPhrase hypertextWords
  211.   global currentTextCast
  212.   
  213.   set numHypertextwords = count(hypertextWords)
  214.   set firstword = getAt(hypertextWords, 1)
  215.   set lastword = firstword + numHypertextwords - 1
  216.   
  217.   set hypertextPhrase = word firstword to lastword of field currentTextCast
  218.   
  219.   repeat while endsWithPunctuation(hypertextPhrase)
  220.     set hypertextPhrase = removePunctuationFromEnd(hypertextPhrase)
  221.   end repeat
  222.   
  223.   return hypertextPhrase
  224. end
  225.  
  226. -- --------------------------------------------------------
  227. -- Handler showSelectedMedia is called when the user clicks
  228. -- on a hyperMedia link. It DOES WHAT?
  229.  
  230. on showSelectedMedia
  231.   alert "you clicked on a hypermedia link"
  232. end